package com.zsw.alancomicserver.controller.background;

import com.zsw.alancomicserver.util.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;

/**
 * 文件上传
 */
@Controller
@RequestMapping("/file")
public class FileTransferController {

    @Value("${fileDir}")
    private String fileDir;

    @PostMapping("/img/up")
    public String uploadImage(@RequestParam("file") MultipartFile file) throws IOException {
        if (file == null || file.isEmpty()) {
            return "error";
        }

        //图片存储到本地
        FileUtil.saveFile(file, fileDir);

        return "success";
    }


}
